package com.zxy.ziems.server.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zxy.btp.common.response.JsonResponse;
import com.zxy.btp.common.response.PageResult;
import com.zxy.ziems.server.domain.AgreementChannel;
import com.zxy.ziems.server.domain.ChannelEquip;
import com.zxy.ziems.server.dto.AgreementChannelDto;
import com.zxy.ziems.server.dto.AgreementChannelQueryDto;
import com.zxy.ziems.server.dto.ChannelEquipDto;
import com.zxy.ziems.server.dto.ChannelEquipQueryDto;
import com.zxy.ziems.server.service.AgreementChannelService;
import com.zxy.ziems.server.service.ChannelEquipService;
import com.zxy.ziems.server.vo.AgreementChannelVo;
import com.zxy.ziems.server.vo.ChannelEquipVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName ChannelEquipController
 * @Description
 * @Author 邓伟
 * @Date 2023/11/29 15:54
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/channelEquip")
public class ChannelEquipController {

    @Autowired
    private ChannelEquipService channelEquipService;

    @PostMapping("/addOrUpdate")
    public JsonResponse addOrUpdate (@RequestBody @Validated ChannelEquipDto channelEquipDto) {
        channelEquipService.addOrUpdate(channelEquipDto);
        return JsonResponse.SUCCESS();
    }

    @GetMapping("/delete")
    public JsonResponse delete (@RequestParam(value = "equipId") String equipId) {
        channelEquipService.delete(equipId);
        return JsonResponse.SUCCESS();
    }

    @PostMapping("/page/list")
    public JsonResponse<PageResult<ChannelEquipVo>> pageList (@RequestBody ChannelEquipQueryDto channelEquipQueryDto) {
        PageResult<ChannelEquipVo> pageResult = channelEquipService.pageList(channelEquipQueryDto);
        return JsonResponse.SUCCESS(pageResult);
    }

    @GetMapping("/list")
    public JsonResponse<List<ChannelEquip>> list (@RequestParam(value = "channelId") String channelId) {
        QueryWrapper<ChannelEquip> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ChannelEquip::getChannelId,channelId);
        List<ChannelEquip> list = channelEquipService.list(queryWrapper);
        return JsonResponse.SUCCESS(list);
    }

    @GetMapping("/getDetail")
    public JsonResponse<ChannelEquipVo> detail (@RequestParam(value = "equipId") String equipId) {
        ChannelEquipVo channelEquipVo = channelEquipService.detail(equipId);
        return JsonResponse.SUCCESS(channelEquipVo);
    }

}
